package bao;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;

public class LoginForm {
    private JFrame f;

    public LoginForm() throws IOException {
        f = new JFrame("登录页面");
        f.setSize(600, 450);
        f.setLocation(400, 300);
        f.setLayout(new GridLayout(4, 1));
        JPanel p1 = new JPanel();
        JLabel l1 = new JLabel("江湖美食系统");
        p1.add(l1);
        JLabel l2 = new JLabel("店长");
        JTextField tf1 = new JTextField(20);
        JPanel p2 = new JPanel();
        p2.add(l2);
        p2.add(tf1);
        JLabel l3 = new JLabel("密码");
        JTextField tf2 = new JTextField(20);
        JPanel p3 = new JPanel();
        p3.add(l3);
        p3.add(tf2);
        JButton b1 = new JButton("登录");
        b1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (tf1.getText().equals("") || tf2.getText().equals("")) {
                    JOptionPane.showMessageDialog(f, "用户名和密码均不能为空", "警告", 3);
                } else {
                    String inname = tf1.getText();
                    String pwd = tf2.getText();
                    LoginCommand command=new LoginCommand();
                    if (!command.login(inname,pwd)) {
                        JOptionPane.showMessageDialog(f, "用户名或密码不正确", "警告", 3);
                    } else {
                        f.setVisible(false);
                        MainForm m = new MainForm();
                    }
                }
            }
        });
        JPanel p4 = new JPanel();
        p4.add(b1);
        f.add(p1);
        f.add(p2);
        f.add(p3);
        f.add(p4);
        p2.setBackground(Color.blue);
        p1.setBackground(Color.blue);
        p3.setBackground(Color.blue);
        f.setBackground(Color.BLUE);
        f.setVisible(true);
    }
}